package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("checkgroup")
@Slf4j
public class CheckGroupController {
    @DubboReference
    private CheckGroupService checkGroupService;

    @GetMapping("findByPage")
    public Result findByPage(QueryPageBean queryPageBean) {
        PageResult byPage = checkGroupService.findByPage(queryPageBean);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, byPage);
    }

    @PostMapping("add")
    public Result add(@RequestBody CheckGroup checkGroup, Integer[] checkitemIds) {
        checkGroupService.add(checkGroup, checkitemIds);
        return new Result(true, MessageConst.ADD_CHECKGROUP_SUCCESS);

    }

    @GetMapping("findById")
    public Result findById(Integer id) {
        CheckGroup byId = checkGroupService.findById(id);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, byId);
    }

    @GetMapping("findCheckitemIds")
    public Result findCheckitemIds(Integer id) {
        List<Integer> checkitemIds = checkGroupService.findCheckitemIds(id);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, checkitemIds);

    }

    @PostMapping("edit")
    public Result edit(@RequestBody CheckGroup checkGroup, Integer[] checkitemIds) {
        checkGroupService.edit(checkGroup, checkitemIds);
        return new Result(true, MessageConst.EDIT_CHECKGROUP_SUCCESS);
    }

    @GetMapping("findAll")
    public Result findAll() {
        List<CheckGroup> all = checkGroupService.findAll();
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, all);
    }
}
